package br.rui.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.rui.dominio.Associacao;
import br.rui.persistencia.ContaDB;

/**
 * Servlet Class
 *
 * @web.servlet              name="NovaAssoc"
 *                           display-name="Name for NovaAssoc"
 *                           description="Description for NovaAssoc"
 * @web.servlet-mapping      url-pattern="/NovaAssoc"
 * @web.servlet-init-param   name="A parameter"
 *                           value="A value"
 */
@SuppressWarnings("serial")
public class NovaAssoc extends HttpServlet {

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,
		IOException {
		ContaDB contadb = new ContaDB ();
		RequestDispatcher rd = null;
		
		int codRui = Integer.parseInt(req.getParameter("codRui"));
		int codOutros = Integer.parseInt(req.getParameter("codFornec"));
		String codCliente = req.getParameter("codCliente");
		String razaosocial = req.getParameter("rzFornec");
		String descricaorui = req.getParameter("descRui");
		
		contadb.CadastraAssociacao(new Associacao(codRui,codOutros,codCliente,razaosocial,descricaorui));
		ArrayList associados = (ArrayList) contadb.Associados();
		req.setAttribute("associados",associados);
		rd = getServletContext().getRequestDispatcher("/web/jsp/Dessassoc.jsp");
			
		rd.forward(req,resp);
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException,
		IOException {
		doGet(req,resp);
	}

}
